<template>
  <div class="app-container">
    <!-- 顶部搜索 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="zjName">
        <el-input size="mini"
                  v-model="queryParams.zjName"
                  placeholder="请输入姓名"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="xb">
        <el-select size="mini" v-model="queryParams.xb" placeholder="请选择性别" clearable>
          <el-option
            v-for="dict in dict.type.xb"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="专业" prop="zy">
        <el-select size="mini" v-model="queryParams.zy" placeholder="请选择专业" clearable>
          <el-option
            v-for="dict in dict.type.pszj_zy"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="专家组" prop="zjz">
        <el-select size="mini" v-model="queryParams.zjz" placeholder="请选择专家组" clearable>
          <el-option
            v-for="dict in dict.type.pszj_zjz"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 顶部按钮 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['zjgl:pszjgl:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['zjgl:pszjgl:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['zjgl:pszjgl:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['zjgl:pszjgl:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 表格 -->
    <el-table @row-click="clickRow" ref="table" highlight-current-row
              :header-cell-style="{background:'#d0cece',color:'#000000',fontWeight:'bold'}"
              v-loading="loading" :data="pszjglList" @selection-change="handleSelectionChange">
      <!--      <el-table-column type="selection" width="55" align="center"/>-->
      <el-table-column label="序号" align="center" type="index" :index="indexMethod"/>
      <el-table-column label="姓名" align="center" prop="zjName"/>
      <el-table-column label="专家组" align="center" prop="zjz">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.pszj_zjz" :value="scope.row.zjz"/>
        </template>
      </el-table-column>
      <el-table-column label="性别" align="center" prop="xb">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.xb" :value="scope.row.xb"/>
        </template>
      </el-table-column>
      <el-table-column label="联系电话" align="center" prop="lxDh"/>
      <el-table-column label="专业" align="center" prop="zy">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.pszj_zy" :value="scope.row.zy"/>
        </template>
      </el-table-column>
      <el-table-column label="职称" align="center" prop="zc"/>
      <el-table-column label="工作单位" align="center" prop="gzDw"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['zjgl:pszjgl:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['zjgl:pszjgl:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页组件 -->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改评审专家管理对话框 -->
    <vxe-modal :title="title" v-model="open" width="60%" showFooter show-zoom resize>
      <el-form ref="formDialog" :model="form" :rules="rules" label-width="95px">
        <div style="height: 72vh;">
          <!-- 专家详细信息 -->
          <el-card class="box-card">
            <div slot="header" class="clearfix" style="text-align: center;">
              <span style="font-size: 20px; color: #1890ff">专家详细信息</span>
            </div>
            <el-row :gutter="24">
              <el-col :span="8">
                <el-form-item label="姓名" prop="zjName">
                  <el-input v-model="form.zjName" placeholder="请输入姓名"/>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="性别" prop="xb">
                  <el-select v-model="form.xb" placeholder="请选择性别">
                    <el-option
                      v-for="dict in dict.type.xb"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="年龄" prop="nl">
                  <el-input type="number" v-model="form.nl" placeholder="请输入年龄"/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="24">
              <el-col :span="8">
                <el-form-item label="联系电话" prop="lxDh">
                  <el-input v-model="form.lxDh" placeholder="请输入联系电话"/>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="专业" prop="zy">
                  <el-select v-model="form.zy" placeholder="请选择专业">
                    <el-option
                      v-for="dict in dict.type.pszj_zy"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="职称" prop="zc">
                  <el-input v-model="form.zc" placeholder="请输入职称"/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="24">
              <el-col :span="8">
                <el-form-item label="办公电话" prop="bgDh">
                  <el-input v-model="form.bgDh" placeholder="请输入办公电话"/>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="QQ号码" prop="qqHm">
                  <el-input v-model="form.qqHm" placeholder="请输入QQ号码"/>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="工作年限" prop="gzNx">
                  <el-input type="number" v-model="form.gzNx" placeholder="请输入工作年限"/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="24">
              <el-col :span="8">
                <el-form-item label="学历" prop="xl">
                  <el-input v-model="form.xl" placeholder="请输入学历"/>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="政治面貌" prop="zzMm">
                  <el-input v-model="form.zzMm" placeholder="请输入政治面貌"/>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="毕业院校" prop="byYx">
                  <el-input v-model="form.byYx" placeholder="请输入毕业院校"/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="24">
              <el-col :span="8">
                <el-form-item label="专家组" prop="zjz">
                  <el-select v-model="form.zjz" placeholder="请选择专家组">
                    <el-option
                      v-for="dict in dict.type.pszj_zjz"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="工作单位" prop="gzDw">
                  <el-input v-model="form.gzDw" placeholder="请输入工作单位"/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-form-item label="特长描述" prop="tcMs">
              <el-input v-model="form.tcMs" type="textarea" placeholder="请输入内容"/>
            </el-form-item>
            <el-form-item label="工作经验" prop="gzJy">
              <el-input v-model="form.gzJy" type="textarea" placeholder="请输入内容"/>
            </el-form-item>
          </el-card>
          <br>
          <!-- 专家登录信息 -->
          <el-card class="box-card">
            <div slot="header" class="clearfix" style="text-align: center;">
              <span style="font-size: 20px; color: #1890ff">专家登录信息(已有账号会自动关联, 没有将新建)</span>
            </div>
            <el-row :gutter="24">
              <el-col :span="12">
                <el-form-item label="用户登录名" prop="userName">
                  <el-input v-model="form.userName" placeholder="请输入用户登录名"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="用户昵称" prop="nickName">
                  <el-input v-model="form.nickName" placeholder="请输入用户昵称"/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="24">
              <el-col :span="12">
                <el-form-item label="登录密码" prop="password">
                  <el-input v-model="form.password" placeholder="请输入登录密码"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="帐号状态" prop="status">
                  <el-select v-model="form.status" placeholder="请选择帐号状态">
                    <el-option
                      v-for="dict in dict.type.sys_normal_disable"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </el-card>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer dialog-footer-center">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </vxe-modal>
  </div>
</template>

<script>
import {addPszjgl, delPszjgl, getPszjgl, getPsZjGlId, listPszjgl, updatePszjgl} from "@/api/zjgl/pszjgl";

export default {
  name: "Pszjgl",
  dicts: ['xb', 'pszj_zjz', 'pszj_zy', 'sys_normal_disable'],
  data() {
    return {
      getPsZjGlId: null, //从后端获取的评审专家管理主键ID (UUID)
      selectedRow: null, // 保存当前选中的行
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 评审专家管理表格数据
      pszjglList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        zjName: null,
        xb: null,
        zy: null,
        zjz: null,
        userId: null,
        deptId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        zjName: [{required: true, message: "姓名不能为空", trigger: "blur"}],
        xb: [{required: true, message: "性别不能为空", trigger: "change"}],
        nl: [{required: true, message: "年龄不能为空", trigger: "blur"}],
        lxDh: [{required: true, message: "联系电话不能为空", trigger: "blur"}],
        zy: [{required: true, message: "专业不能为空", trigger: "change"}],
        zc: [{required: true, message: "职称不能为空", trigger: "blur"}],
        userName: [{required: true, message: "用户登录名不能为空", trigger: "blur"}],
        nickName: [{required: true, message: "用户昵称不能为空", trigger: "blur"}],
        password: [{required: true, message: "登录密码不能为空", trigger: "blur"}],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 自定义序号 */
    indexMethod(index) {
      let pageNum = this.queryParams.pageNum - 1;
      if ((pageNum !== -1 && pageNum !== 0)) {
        return (index + 1) + (pageNum * this.queryParams.pageSize);
      } else {
        return (index + 1)
      }
    },
    //点击行 获取行
    clickRow(row) {
      this.selectedRow = row; // 更新选中的行
      const table = this.$refs.table;
      const selectedRows = table.selection;

      // 否则取消之前选中的行，并选中当前点击的行
      selectedRows.forEach(selectedRow => {
        table.toggleRowSelection(selectedRow);
      });
      table.toggleRowSelection(row);
    },
    /** 查询评审专家管理列表 */
    getList() {
      this.loading = true;
      listPszjgl(this.queryParams).then(response => {
        this.pszjglList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        pszjglId: this.getPsZjGlId,
        zjName: null,
        xb: '男',
        nl: null,
        lxDh: null,
        zy: null,
        zc: null,
        bgDh: null,
        qqHm: null,
        gzNx: 0,
        xl: null,
        zzMm: null,
        byYx: null,
        zjz: null,
        gzDw: null,
        tcMs: null,
        gzJy: null,
        userName: null,
        nickName: null,
        password: null,
        status: '0',
        idWhere: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        userId: null,
        deptId: null
      };
      this.resetForm("formDialog");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.pszjglId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      getPsZjGlId().then(res => {
        this.getPsZjGlId = res.msg
        this.reset();
      })
      this.open = true;
      this.title = "添加评审专家管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const pszjglId = row.pszjglId || this.ids
      getPszjgl(pszjglId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改评审专家管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["formDialog"].validate(valid => {
        if (valid) {
          if (this.form.idWhere != null) { //修改
            updatePszjgl(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else { //新增
            addPszjgl(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const pszjglIds = row.pszjglId || this.ids;
      this.$modal.confirm('确定删除选中记录？').then(function () {
        return delPszjgl(pszjglIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('zjgl/pszjgl/export', {
        ...this.queryParams
      }, `pszjgl_${new Date().getTime()}.xlsx`)
    },
  }
};
</script>
